package com.cicc.springboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cicc.springboot.common.dto.R;
import com.cicc.springboot.entity.MaterialZmaraEntity;
import com.cicc.springboot.model.MaterialQuery;
import com.cicc.springboot.service.MaterialInformationService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName MaterialInfoController
 * @Description TODO
 * @Author 转轮王
 * @Date 2024/9/27 11:42
 * @Version 1.0
 */


@RestController
@RequestMapping("/material-information")
@AllArgsConstructor
public class MaterialInfoController {
    @Autowired
    private MaterialInformationService materialService;


    /**
     * 列表展示物料信息
     *
     * @param currentPage
     * @param pageSize
     * @param materialName
     * @param materialNumber
     * @param materialType
     * @param materialStatus
     * @return
     */
    @GetMapping("/materials")
    public R<Page<MaterialZmaraEntity>> queryMaterials(@RequestParam("currentPage") int currentPage,
                                                       @RequestParam("pageSize") int pageSize,
                                                       @RequestParam(value = "materialName", required = false) String materialName,
                                                       @RequestParam(value = "materialNumber", required = false) String materialNumber,
                                                       @RequestParam(value = "materialType", required = false) String materialType,
                                                       @RequestParam(value = "materialStatus", required = false) String materialStatus) {
        return materialService.queryMaterialsPage(currentPage, pageSize, materialName, materialNumber, materialType, materialStatus);
    }


    /**
     * 新增或修改物料
     *
     * @param materialQuery
     * @return
     */

    @PostMapping("/saveMaterial")
    public R<MaterialZmaraEntity> saveMaterial(@RequestBody MaterialQuery materialQuery) {
        System.out.println(materialQuery.toString());
        return materialService.saveMaterial(materialQuery);
    }


    /**
     * 删除物料信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteMaterial")
    public R<Integer> deleteMaterial(@RequestParam("id") long id) {
//        System.out.println("接收到的id是"+id);
        return materialService.deleteMaterial(id);
    }

    /**
     * 根据id修改物料的状态码
     */
    @PutMapping("/updateMaterialState")
    public R<String> updateMaterialState(@RequestParam("materialId") long materialId) {
        return materialService.updateMaterialState(materialId);
    }

    /**
     * 根据id查看详情
     */

    @GetMapping("/getMaterialById")
    public R<MaterialZmaraEntity> getMaterialById(@RequestParam("id") long id) {
        return materialService.getMaterialById(id);
    }


}
